<?php

/**
 * Description of Visitors Model
 *
 * @author Lugol Metayer
 */

 
 class Visits_Info extends Model {

	/*
	 * Used to retrieve the appointment for the visit table
	 * @return array
	 */
		public function retrieve_visit()
		{
		 
		 return $this->db->query('SELECT v.visit_id, v.purpose, DATE_FORMAT(v.visit_date, \'%Y-%m-%d\') as visit_date ,TIME_FORMAT(v.visit_time, \'%l:%i\') as visit_time, p.pet_name, p.pet_id  FROM visits v INNER JOIN pets p ON v.pet_id = p.pet_id where CURDATE() <= v.visit_date ORDER BY v.visit_date, v.visit_time;')->result();
		 
		}
		/*
	 * Used to retrieve the appointment details for the visit table
		*@param visit_id for the where statement 
	 * @return array
	 */
		public function detail_visit($where)
		{
				$sql = "SELECT v.visit_id, DATE_FORMAT(v.visit_date, '%Y-%m-%d') as visit_date ,TIME_FORMAT(v.visit_time, '%l:%i') as visit_time, v.action, v.doctor_notes, v.other_notes, v.purpose, p.*  FROM visits v INNER JOIN pets p ON v.pet_id = p.pet_id where v.visit_id = ?;";
				return $this->db->query($sql,array($where))->result();
		}
		/*
	 * Insert the visit in to the visit table
		*@param pet_id
		 * @param visit date
		 * @param visit time
		 * @param visit purpose
		 * @param visit action
		 *  @param doctor notes
		 *  @param other notes
	 * @return array
	 */
		public function insert_visit($pet_id,$visit_date,$visit_time,$purpose,$action,$doc_notes,$other_notes){
				$data = array('pet_id'=>$pet_id, 'visit_date'=>$visit_date, 'visit_time'=>$visit_time, 'purpose'=>$purpose, 'action'=>$action, 'doctor_notes'=>$doc_notes, 'other_notes'=>$other_notes);

				$str = $this->db->insert_string('visits', $data);
				
				$query = $this->db->query($str);


		}
		/*
	 * Insert the visit in to the visit table
		*@param id for the where statement 
		 * @param visit date
		 * @param visit time
		 * @param visit purpose
		 * @param visit action
		 *  @param doctor notes
		 *  @param other notes
	 * @return array
	 */
		public function update_visit($id,$visit_date,$visit_time,$purpose,$action,$doc_notes,$other_notes){

				$datetime = date("l:i", strtotime("$visit_time"));
				$data = array('visit_date'=>$visit_date, 'visit_time'=>$visit_time, 'purpose'=>$purpose, 'action'=>$action, 'doctor_notes'=>$doc_notes, 'other_notes'=>$other_notes);

				$where = "visit_id = $id";

				$str = $this->db->update_string('visits', $data, $where);
				
				$query = $this->db->query($str);
		}
		public function delete_visit($where){
				$sql = "DELETE FROM visit where visit_id = ?;";
				return $this->db->query($sql,array($where));
		}
		
//*EOF*//	
}	
